package offer.binarytree;


import java.util.Stack;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/20 22:12
 */
public class BinaryPath25 {

    public static void findPath(BinaryTree<Integer> head, int desNum) {
        if (head == null)
            return;
        Stack<BinaryTree<Integer>> stack = new Stack<>();
        findPath(head, 0, stack, desNum);
    }

    private static void findPath(BinaryTree<Integer> head, int currentSum, Stack<BinaryTree<Integer>> stack, int desNum) {
        if (head == null)
            return;
        stack.push(head);
        currentSum += head.value;
        if (head.left == null && head.right == null) {
            if (currentSum == desNum) {
                for (int i = 0; i < stack.size(); i++) {
                    System.out.print(stack.elementAt(i).value + " ");
                }
                System.out.println();
            }
        }

        findPath(head.left, currentSum, stack, desNum);
        findPath(head.right, currentSum, stack, desNum);

        stack.pop();

    }


    static class Test{
        private int i = 0;
        public Test() {
            System.out.println("Constractor");
        }

        public static void main(String[] args) {
            Test[] test = new Test[12];
        }
    }


}
